import { createRouter, createWebHashHistory, createWebHistory, RouterOptions, Router } from 'vue-router'
import routes from './routes'
import store from './../store/index'
const router = createRouter({
  history: createWebHistory(),
  routes
})
let userStore: any = store;
router.beforeEach((to, from, next) => {
  if (to.path == '/login') {
    next()
  } else {
    if (to.meta.requireAuth) {
      if (userStore.state.user.token) {
        next()
      } else {
        next({ path: '/login' })
      }
    } else {
      next()
    }
  }
})
export default router